<template>
	<view>
		<view class="main">
			<u-sticky>
				<view class="tag-box">
					<view class="tag-list">
						<view class="tag-item" :class="tagSelect == 1 ? 'active' : ''" @click="tagClick(1)">
							<text>已收取</text>
						</view>
						<view class="tag-item" :class="tagSelect == 2 ? 'active' : ''" @click="tagClick(2)">
							<text>未收取</text>
						</view>
					</view>
				</view>
			</u-sticky>
			<view class="list" v-if="lists && lists.length > 0">
				<view class="item" v-for="(item, index) in lists" :key="index">
					<view class="sn-box">
						<view class="sn">
							<text>{{item.sn}}</text>
						</view>
						<view class="state" :class="tagSelect == 1 ? 'greens' : 'reds'">
							<text v-if="tagSelect == 1">已收取</text>
							<text v-else>待收取</text>
						</view>
					</view>
					<view class="merchant-box">
						<view class="name">
							<text>商户名称</text>
							<text>{{item.merchant_name}}</text>
						</view>
						<view class="merchant">
							<text>商户编号</text>
							<text>{{item.merchant_id}}</text>
						</view>
						<view v-if="item.nums" class="merchant">
							<text>收取次数</text>
							<text>{{item.nums}}</text>
						</view>
					</view>
					<view v-if="tagSelect == 1" class="time-box">
						<view class="time">
							<text>{{item.deduct_time}}</text>
						</view>
						<view class="money">
							<text>{{item.money}}</text>
						</view>
					</view>
				</view>
			</view>
			<u-empty class="policy_box" v-else mode="list" icon="/static/Empty/data_null.png"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tagSelect: 1,
				lists: [],
				page: 1,
				page_size: 10,
				bottom: true,
			}
		},
		onLoad() {
			this.loadData()
		},
		//下拉刷新
		onReachBottom() {
			if (this.bottom == true) {
				this.page += 1
				this.loadData()
			}
		},
		methods: {
			// 选项卡
			tagClick(type) {
				this.tagSelect = type
				this.page = 1
				this.bottom = true
				this.lists = []
				this.loadData()
			},
			// 加载数据
			async loadData() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getHzyFlowDeduct',
					data: {
						page: this.page,
						page_size: this.page_size,
						type: this.tagSelect
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					if (res.data.data !== undefined && res.data.data !== null && res.data.data.length > 0) {
						if (this.page == 1) {
							this.lists = res.data.data
						} else {
							this.lists = [...this.lists, ...res.data.data]
						}
					} else {
						this.bottom = false
					}
				} else {
					this.bottom = false
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.tag-box {
			background-color: #ffffff;
			padding: 30rpx;
			
			.tag-list {
				display: flex;
				justify-content: space-between;
				align-items: center;
				text-align: center;
				border-radius: 20rpx;
				border: 1px solid #2979ff;
				
				.tag-item {
					width: 50%;
					text-align: center;
					align-items: center;
					padding: 18rpx;
					font-size: 28rpx;
					border-radius: 20rpx;
				}
				
				.active {
					color: #ffffff;
					background-color: #2979ff;
				}
			}
		}
		
		.list {
			padding: 0 30rpx 30rpx 30rpx;
			
			.item {
				margin-top: 30rpx;
				padding: 0 30rpx;
				background-color: #ffffff;
				border-radius: 14rpx;
				box-shadow: 0px 0px 20px -12px #342f2f;
				
				.sn-box {
					padding: 30rpx 0;
					display: flex;
					justify-content: space-between;
					border-bottom: 1px solid #c8c9cc;
					align-items: center;
					
					.sn {
						font-weight: bold;
					}
					
					.state {
						font-size: 24rpx;
						padding: 10rpx 20rpx;
						border-radius: 8rpx;
						color: #ffffff;
					}
					
					.greens {
						background-color: #19be6b;
					}
					
					.reds {
						background-color: #fa3534;
					}
				}
				
				.merchant-box {
					.name {
						display: flex;
						justify-content: space-between;
						padding: 30rpx 0;
						border-bottom: 1px solid #f4f4f5;
					}
					
					.merchant {
						display: flex;
						justify-content: space-between;
						border-bottom: 1px solid #f4f4f5;
						padding: 30rpx 0;
					}
				}
				
				.time-box {
					display: flex;
					justify-content: space-between;
					padding: 30rpx 0;
					align-items: center;
					
					.time {
						font-size: 24rpx;
						color: #909399;
					}
					
					.money {
						font-size: 34rpx;
					}
				}
			}
		}
	}
</style>
